package com.cxyd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxyd.domain.School;
import com.cxyd.mapper.SchoolMapper;
import com.cxyd.service.SchoolService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: huanglianyun
 * @Description:
 * @DATE: Created in 2020/2/16 20:38.
 */
@Service("schoolService")
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class SchoolServiceImpl extends ServiceImpl<SchoolMapper, School> implements SchoolService {

    @Autowired
    SchoolMapper schoolMapper;

    @Override
    public void addSchool(School school) {
        schoolMapper.insert(school);
    }

    @Override
    public IPage<School> selectPageSchool(Page<School> page, String schoolName, String schoolHead, String province) {
        QueryWrapper<School> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(schoolName),"school_name",schoolName);
        queryWrapper.like(StringUtils.isNotBlank(schoolHead),"school_head",schoolHead);
        queryWrapper.like(StringUtils.isNotBlank(province),"province",province);
        return this.page(page,queryWrapper);
    }
}
